﻿
using Log.Recorder;
using System.Web.Http;

namespace Demo.Controllers
{
    public class TestController : ApiController
    {

        LogRecorder logger = LogRecorder.Instance;



        [HttpGet]
        public dynamic t1() {

            logger.Debug("dddddddddd");
            logger.Error("dddddddddd");
            logger.Trace("dddddddddd");

            return 10000;
        }
        [HttpGet]
        public dynamic t2(int c=100)
        {

            int count = c;
            for(int ind=0;ind<count; ind++)
            {
                logger.Debug("dddddddddd "+ ind, new { ind = ind });

                logger.Error("dddddddddd " + ind, new { ind = ind });
                logger.Trace("dddddddddd " + ind, new { ind = ind });
                logger.Other("Other.dbd.db", "dddddddddd " + ind, new { ind = ind });
            }
            


            return count;
        }

        [HttpGet]
        public dynamic t3(int c = 100)
        {
            Log.Recorder.LogRecorder logger3 = new Log.Recorder.LogRecorder();
            int count = c;
            for (int ind = 0; ind < count; ind++)
            {
                logger3.Debug("dddddddddd " + ind, new { ind = ind });

                logger3.Error("dddddddddd " + ind, new { ind = ind });
                logger3.Trace("dddddddddd " + ind, new { ind = ind });
                logger3.Other("Other.dbd.db", "dddddddddd " + ind, new { ind = ind });
            }
            logger3.Trace("dddd "  );


            return count;
        }



        [HttpGet]
        public dynamic t4()
        {
            Log.Recorder.LogReader read = new Log.Recorder.LogReader();
            
            return read.GetLogDbFileList();
        }

        [HttpGet]
        public dynamic t5(string f)
        {
            Log.Recorder.LogReader read = new Log.Recorder.LogReader();

            return read.GetLogs(f);
        }
        [HttpGet]
        public dynamic t51(string f, int pageSize=10, int pageNumber=1, string sortField = null, string sortType=null)
        {
            Log.Recorder.LogReader read = new Log.Recorder.LogReader();

            return read.GetLogsByPage(pageSize,pageNumber,sortField,sortType,f,null,null,null,null,null,null);
        }

        [HttpGet]
        public dynamic t6(string f,string i)
        {
            Log.Recorder.LogReader read = new Log.Recorder.LogReader();

            return read.GetLogData(f,i);
        }
        [HttpGet]
        public dynamic t7() {
            
            return new { 
                WriterCount = LogRecorder.WriterCount ,
                Time = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
            };
        }

        [HttpGet]
        public dynamic t8()
        {

            return new
            {
                BaseDirectory = System.AppDomain.CurrentDomain.BaseDirectory,
                WriterCount = LogRecorder.WriterCount,
                ConfigInfo = LogRecorder.ConfigInfo,
            };
        }
        

    }
}
